﻿
Partial Class WebForm_ManageEmployee_SearchEmployee
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Me.BindDDLActive()
            Me.BindDDLOrganizationID()
            RaiseEvent Loaded(Me, New EventArgs)

        End If
    End Sub

    Protected Sub gv_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gv.PageIndexChanging
        Me.gv.PageIndex = e.NewPageIndex
        Me.BindGV()
    End Sub

    Protected Sub gv_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gv.RowEditing
        Me.EmployeeID = Me.gv.DataKeys(e.NewEditIndex)("EmployeeID")
        RaiseEvent Editing(Me, New EventArgs)
    End Sub

    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click
        Me.BindGV()
    End Sub
End Class

Partial Class WebForm_ManageEmployee_SearchEmployee
    Private Sub BindDDLActive()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        Me.ddlActive.DataTextField = "Text"
        Me.ddlActive.DataValueField = "Value"
        Me.ddlActive.DataSource = MyObj.GetCodeMappingData("Employee", "Active")
        Me.ddlActive.DataBind()
    End Sub

    Private Sub BindDDLOrganizationID()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.AppendFormat("select o.* ")
        sql.AppendFormat("from Organization o ")
        sql.AppendFormat("inner join FD_UserOrganizationAuth oa on o.OrganizationID = oa.OrganizationID ")
        sql.AppendFormat("where o.Active = 'Y' ")
        sql.AppendFormat("and oa.UserID = '{0}' ", clsAuth.GetUserID())

        Me.ddlOrganizationID.DataTextField = "OrganizationName"
        Me.ddlOrganizationID.DataValueField = "OrganizationID"
        Me.ddlOrganizationID.DataSource = dat.GetData(sql)
        Me.ddlOrganizationID.DataBind()
    End Sub

    Public Sub BindGV()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim dt As Data.DataTable

        sql.AppendFormat("select e.*, o.OrganizationName ")
        sql.AppendFormat("from FD_Employee e ")
        sql.AppendFormat("inner join Organization o on e.OrganizationID = o.OrganizationID ")
        sql.AppendFormat("WHERE 1=1 ")

        If ddlOrganizationID.SelectedValue <> "2" Then
            sql.AppendFormat(" and o.OrganizationID='{0}'", ddlOrganizationID.SelectedValue.ToString())
        End If
        sql.AppendFormat(" and o.Active='{0}'", ddlActive.SelectedValue.ToString())
        If txtEmployeeID.Text.Trim() <> "" Then
            sql.AppendFormat(" and e.EmployeeID='{0}'", txtEmployeeID.Text.Trim())
        End If
        If txtEmployeeName.Text.Trim() <> "" Then
            sql.AppendFormat(" and e.EmployeeName='{0}'", txtEmployeeName.Text.Trim())
        End If


        dt = dat.GetData(sql)

        Me.gv.DataSource = dt
        Me.gv.DataBind()

    End Sub

    Public Property EmployeeID() As String
        Get
            Return ViewState("EmployeeID")
        End Get
        Set(ByVal value As String)
            ViewState("EmployeeID") = value
        End Set
    End Property

    Public Event Loaded(ByVal source As Object, ByVal e As EventArgs)
    Public Event Editing(ByVal source As Object, ByVal e As EventArgs)
End Class